<template>
  <div class="main">
    <div>
      <fcTable
        ref="table"
        :columes="columes"
        :selection="false"
        :url="this.list"
        :deletUrl="universalUrl"
      >
        <!-- 表上头按钮插槽 -->
        <template v-slot:button>
          <el-button
            icon="el-icon-circle-plus-outline"
            type="primary"
            v-hasPermi="['system']"
            @click="add()"
          >新增
          </el-button
          >
        </template>

        <!-- 表格行插槽 -->
        <template #status="scope">
          <el-tag :type="scope.row.status == 0 ? 'primary' : 'warning'">{{
            scope.row.statusText
            }}
          </el-tag>
        </template>
        <template #wareTypeID="scope">
          <el-tag :type="scope.row.wareTypeID">{{
            scope.row.wareTypeIDText
            }}
          </el-tag>
        </template>
        <template #operation="scope">
          <el-link type="primary" style="margin-right: 5px" @click="edit(scope.row)">编辑</el-link>
        </template>
      </fcTable>
    </div>
    <wareHouseAdd
      :title="title"
      :visible.sync="visible"
      :item="element"
      @Ok="addAndEdit"
    ></wareHouseAdd>
  </div>
</template>
<script>
  import request from "@/utils/request";
  import fcTable from "@/components/futureCloudMOM/fcTable";
  import wareHouseAdd from "./wareHouseAdd";
  import {createLogger} from "vuex";

  export default {
    name: "WareHouse",
    components: {
      fcTable,
      wareHouseAdd,
    },
    data() {
      return {
        columes: [
          {
            label: "仓库编码",
            key: "code",
            visible: true,
          },
          {
            label: "仓库名称",
            key: "name",
            visible: true,
          },
          {
            label: "仓库地址",
            key: "address",
            visible: true,
          },
          {
            label: "联系电话",
            key: "phone",
            visible: true,
          },
          {
            label: "仓库位置agv",
            key: "location",
            visible: true,
          },
          {
            label: "仓库类型",
            key: "wareTypeID",
            visible: true,
            type: "slot",
            //后端通过注解翻译过来的字段
            dictText: "wareTypeIDText",
            dictCode: "basic_housetype",

          },
          {
            label: "ERP对应仓库编码",
            key: "eRPStockNumber",
            visible: true,
          },
          {
            label: "所属部门",
            key: "deptId",
            visible: true,
            type: "slot",

          },
          {
            label: "库存状态",
            key: "stockStatus",
            visible: true,
            dictCode: "warehouse_stockstatus",

          },
          {
            label: "仓库状态",
            key: "status",
            visible: true,
            dictCode: "sys_normal_disable",
          },
          {
            label: "是否上架标记",
            key: "hSJFlag",
            visible: true,
            type: "slot",
          },
          {
            label: "是否先进先出",
            key: "hFIFOFlag",
            visible: true,
            type: "slot",
          },
          {
            label: "是否参与APS计算",
            key: "aPSFlag",
            visible: true,
            type: "slot",
          },
          {
            label: "是否倒冲",
            key: "recoilFlag",
            visible: true,
            type: "slot",
          },
          {
            label: "是否允许超量入库",
            key: "lnflag",
            visible: true,
            type: "slot",
          },
          {
            label: "是否允许超量领用",
            key: "outflag",
            visible: true,
            type: "slot",
          },

          {
            label: "备注",
            key: "remark",
            visible: true,
            search: true,
          },
          {
            label: "操作",
            key: "operation",
            //是否支持删除功能
            delete: true,
            //插槽需要的属性
            type: "slot",
            fixed: "right",
            //显隐列需要的属性
            visible: true,
            disabled: true,
            //不支持搜索 写入
            search: true,
          },
        ],
        //新增/编辑弹窗打开的标题
        title: "",
        //显隐
        visible: false,
        //数据
        element: {},
        //列表页
        list: "basic/warehouse/getList",
        //新增 修改 删除
        universalUrl: "basic/warehouse",
      };
    },

    methods: {
      add() {
        this.element = null;
        this.title = "新增";
        this.visible = true;
      },
      edit(item) {
        console.log(item);
        this.element = item;
        this.title = "编辑";
        this.visible = true;
      },
      addAndEdit(item) {
        console.log(item);
        let method = "put";
        if (this.title === "新增") {
          method = "post";
        }
        request({
          url: this.universalUrl,
          method: method,
          data: item,
        }).then((res) => {
          if (res.code === 200) {
            this.$message.success("操作成功");
            this.$refs.table.getList();
            this.visible = false;
          } else {
            this.$message.error(res.message);
          }
        });
      },
      //开关修改状态
      editByStatus(item) {
        request({
          url: this.universalUrl,
          method: "put",
          data: item,
        }).then((res) => {
          if (res.code === 200) {
            this.$message.success("操作成功");
            this.$refs.table.getList();
          } else {
            this.$message.error(res.message);
          }
        });
      },
    },
  };
</script>
<style scoped>
  .main {
  }
</style>
